<template>
  <view class="list">
    <template v-for="(item, i) in tList" :key="item.id">
      <question
        v-if="cId === item.id"
        class="item"
        :disabled="disabled"
        :item="item"
        :i="i"
        :start="start"
        :cWidth="cWidth"
        :tWidth="tWidth"
        :max="max ? max : tList.length"
        @change="onChange"
      />
    </template>
  </view>
</template>

<script lang="ts">
import Question from './question.vue'
export default {
  props: {
    disabled: {
      default: false
    },
    start: {
      default: 0
    },
    max: {
      default: 0
    },
    List: {
      default: () => {
        return []
      }
    },
    cWidth: {
      default: () => {
        return uni.upx2px(750 - 64)
      }
    },
    cId: {
      default: ''
    }
  },
  components: {
    Question
  },
  watch: {
    List: {
      handler(val) {
        this.tList = val.filter((v) => {
          if (v.exc && Object.prototype.hasOwnProperty.call(v.exc, 'show') && !v.exc.show) {
            return false
          }
          return true
        })
      },
      immediate: true
    }
  },
  data() {
    return {
      tList: []
    }
  },
  computed: {
    tWidth() {
      return (this.cWidth - uni.upx2px(20)) / 2
    }
  },
  methods: {
    onChange() {
      this.$emit('change')
    }
  }
}
</script>

<style lang="scss" scoped>
.item {
  width: 100%;
  background-color: #fff;
  border-radius: 16rpx 16rpx 16rpx 16rpx;
  &:not(:first-child) {
    margin-top: 32rpx;
  }
  .title {
    width: 100%;
    padding: 0 32rpx;
    font-size: 32rpx;
    color: #222222;
    line-height: 52rpx;
    display: flex;
    align-items: flex-start;
    word-break: break-all;
    .no {
      margin-top: 10rpx;
      height: 34rpx;
      flex: 0 0 auto;
      font-family: PingFang SC;
      font-weight: 500;
      font-size: 24rpx;
      color: #686868;
      line-height: 34rpx;
      margin-right: 8rpx;
      white-space: nowrap;
    }
    .text {
      flex: 1 1 auto;
      display: flex;
      flex-direction: column;
      // .text_name {
      //   display: flex;
      //   flex-direction: row;
      // }
    }
    .error {
      margin-top: 8rpx;
      display: inline-block;
      background: #ff503d;
      border-radius: 4rpx 4rpx 4rpx 4rpx;
      padding: 4rpx 16rpx 2rpx 16rpx;
      font-family: PingFang SC;
      font-weight: 500;
      font-size: 24rpx;
      color: #ffffff;
      line-height: 34rpx;
      word-break: break-all;
    }
    .mark {
      margin-top: 6rpx;
      display: inline-block;
      width: 80rpx;
      height: 40rpx;
      background: #5c8eff;
      border-radius: 4rpx 4rpx 4rpx 4rpx;
      margin-left: 8rpx;
      font-family: PingFang SC;
      font-weight: 500;
      font-size: 24rpx;
      color: #ffffff;
      text-align: center;
      line-height: 40rpx;
    }
  }
}
.aInput {
  .content {
    width: 100%;
    padding: 0 32rpx;
    .input {
      width: 100%;
      height: 108rpx;
      font-size: 32rpx;
      color: #222222;
      line-height: 100rpx;
      border-bottom: 2rpx solid #222222;
    }
  }
}
.aSelect {
  .options {
    width: 100%;
    margin-top: 32rpx;
    padding: 0 32rpx;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 20rpx;
    box-sizing: border-box;
  }
}
.aSearch {
  .content {
    margin-top: 24rpx;
    width: 100%;
    padding: 0 32rpx;
    .box {
      width: 100%;
      height: 84rpx;
      position: relative;
    }
    .search {
      width: 100%;
      height: 84rpx;
      padding: 0 24rpx;
      background: #ffffff;
      border-radius: 42rpx;
      border: 2rpx solid #000000;
      display: flex;
      align-items: center;
      .input {
        width: 100%;
        height: 42rpx;
        font-family: PingFang SC;
        font-weight: 400;
        font-size: 30rpx;
        color: #222222;
        line-height: 42rpx;
      }
    }
    .mask {
      z-index: 10;
      height: 84rpx;
      width: 100%;
      position: absolute;
      top: 0;
      left: 0;
    }
  }
}
</style>
